var Main = {
    projectConfigId: ""
};

layui.use(['element', 'layer'], function() {
    var $ = layui.jquery,
        element = layui.element,
        layer = layui.layer;

    // 选择项目
    Main.checkProject = function(projectConfigId, projectName) {
        $("#currentProject").html(projectName + '<span class="layui-nav-more"></span>');

        Main.projectConfigId = projectConfigId;
        Main.localStorageSet("currentProject", {"projectConfigId": projectConfigId, "projectName": projectName});
    }

    Main.init = function() {
        // 当前项目
        var currentProject = Main.localStorageGet("currentProject");
        if(currentProject) {
            Main.checkProject(currentProject.projectConfigId, currentProject.projectName);
        }
    }();
});




Main.checkRes = function(res) {
    if(res == null || (res != null && res.code == "error")) {
        return false;
    }

    return true;
};

Main.getUrlParam = function(paramName) {
    var reg = new RegExp("(^|&)"+ paramName +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r != null) return unescape(r[2]); return null;
};

/**
 * 往localStorage中存值
 */
Main.localStorageSet = function(key, value) {
    if(typeof value != "string") {
        try {
            value = JSON.stringify(value);
        } catch(e) {
            console.warn(e);
        }
    }

    localStorage.setItem(key, value);
};

/**
 * 从localStorage中取值
 */
Main.localStorageGet = function(key) {
    var value = localStorage.getItem(key);
    if(!value) return value;

    try {
        value = JSON.parse(value);
    } catch(e) {}

    return value;
};
